python writing binary data to a file